package org.sbbs.app.gen.webapp.action;

import org.sbbs.app.gen.model.GenEntity;
import org.sbbs.base.searcher.SearchFilterBuilder;
import org.sbbs.base.webapp.action.BaseJqgridPagedAction;
import org.sbbs.app.gen.service.GenEntityManager;
import org.sbbs.base.pager.IPager;
import org.sbbs.base.pager.impl.JqgridPagerImpl;
import org.sbbs.base.searcher.SearchFilter;
public class GenEntityPagedAction extends BaseJqgridPagedAction {
	private GenEntityManager	genEntityManager;
	public GenEntityManager getGenEntityManager() {
		return genEntityManager;
	}

	public void setGenEntityManager(GenEntityManager genEntityManager) {
		this.genEntityManager = genEntityManager;
	}
	@Override
	public Class getSearchEntityClazz() {
		return GenEntity.class;
	}

	@Override
	public int getSearchFilterType() {
		return SearchFilterBuilder.PROPERTY_FILTER;
	}

	@Override
	public String gridPageList() {
        this.setSearchFilterType( SearchFilterBuilder.PROPERTY_FILTER );
        try {
            IPager pager = new JqgridPagerImpl( getRequest() );
            SearchFilter sf = SearchFilterBuilder.buildSearchFilter( getRequest(), this.getSearchFilterType() );
            if ( this.getCustomCriteria() != null )
                pager = this.genEntityManager.pagedQuery( this.getSearchEntityClazz(), pager, sf, this.getCustomCriteria() );
            else
                pager = this.genEntityManager.pagedQuery( this.getSearchEntityClazz(), pager, sf );

            this.pageList = pager.getList();
            records = pager.getTotalNumberOfRows();
            total = pager.getTotalNumberOfPages();
            page = pager.getPageNumber();
        }
        catch ( Exception e ) {
            log.error( "genEntityGridList Error", e );
        }
        return SUCCESS;
    }
}
